﻿using System;
using System.Net;
using System.Text;

using zijian666.Abstractions;
using zijian666.ConvertExtensions;

namespace zijian666.Translator;

/// <summary>
/// 字符串翻译器
/// </summary>
public class StringTranslator : ITranslator
{
    /// <inheritdoc />
    public bool TryTranslate(IConvertContext context, object? input, out object? translated)
    {
        translated = input switch
        {
            StringBuilder stringBuilder => stringBuilder.ToString(),
            Uri uri => uri.ToString(),
            IPAddress ipAddress => ipAddress.ToString(),
            IFormattable formattable => context.Settings.Format(formattable),
            _ => null,
        };
        return translated is not null;
    }
}
